home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / awe / awe-full.lha / Awe2 / DoNotUseThisSrc / SimulationMultiplexor.cc < prev    next >
C/C++ Source or Header  |  1990-08-08  |  4KB  |  187 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. //
  5. // written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  6. //
  7.  
  8. #ifdef __GNUG__
  9. #  pragma implementation
  10. #endif
  11.  
  12. #include "SimulationMultiplexor.h"
  13. #include "CpuMultiplexorP.h"
  14. #include "CpuMuxExceptions.h"
  15. #include "HardwareContextP.h"
  16. #include "SpinLock.h"
  17. #include "SpinBarrier.h"
  18. #include "SpinFetchAndOp.h"
  19. #include "AwesimeHeap.h"
  20.  
  21. #include "Thread.h"
  22.  
  23. #include "TimeSchedulerSplayPQ.h"
  24.  
  25. #include "ReserveByException.h"
  26. #include <math.h>
  27.  
  28. #include "Debug.h"
  29.  
  30. static const int NOTREACHED = 0;
  31.  
  32. SimulationMultiplexor *ThisSimulationMultiplexor;
  33.  
  34. double CurrentSimulatedTime = 0.0;
  35.  
  36. extern int CpuMuxDebugFlag;
  37.  
  38. SimulationMultiplexor::SimulationMultiplexor(int debug)
  39. {
  40.     ThisSimulationMultiplexor = this;
  41.     CpuMuxDebugFlag = debug;
  42. }
  43.  
  44. SimulationMultiplexor::~SimulationMultiplexor()
  45. {
  46.     // empty
  47. }
  48.  
  49. //void
  50. //SimulationMultiplexor::allocateLocalEventStructures(int newIYam, int outOf)
  51. //{
  52. //    // empty
  53. //}
  54.  
  55. void
  56. SimulationMultiplexor::allocateEventStructures(int, int)
  57. {
  58.     assert( NOTREACHED );
  59. }
  60.  
  61. void
  62. SimulationMultiplexor::deallocateEventStructures()
  63. {
  64.     assert( NOTREACHED );
  65. }
  66.  
  67. #ifdef UNDEF
  68. void
  69. SimulationMultiplexor::fireItUp( int cpus, unsigned )
  70. {
  71.     warmThePot( cpus );
  72.     stirItAround();
  73.     coolItDown();
  74. }
  75.  
  76. void
  77. SimulationMultiplexor::warmThePot(int)
  78. {
  79.     assert( NOTREACHED );
  80. }
  81.  
  82. void
  83. SimulationMultiplexor::stirItAround()
  84. {
  85.     assert( NOTREACHED );
  86. }
  87.  
  88. void
  89. SimulationMultiplexor::coolItDown()
  90. {
  91.     assert( NOTREACHED );
  92. }
  93. #endif
  94.  
  95. void
  96. SimulationMultiplexor::addAt(Thread *who, double when)
  97. {
  98.     if (when <= CurrentSimulatedTime) {
  99.     ThisCpu -> add(who);
  100.     }
  101.     else {
  102. #ifndef NDEBUG
  103.     if (CpuMuxDebugFlag) {
  104.         CpuCerrLock.reserve();
  105.         cerr << ThisCpu -> name();
  106.         cerr << " add " << who -> name();
  107.         cerr << " to pending for " << when << "\n";
  108.         CpuCerrLock.release();
  109.     }
  110. #endif /* NDEBUG */
  111.     //
  112.     // Add them to pending events
  113.     //
  114.     TimeScheduler item(who,when);
  115.     DEBUG_START;
  116.     cerr << ThisCpu -> name();
  117.     cerr << " item added is " << hex(long(item.thread()));
  118.     cerr << " " << item.time() << "\n";
  119.     DEBUG_END;
  120.     myPendingEvents->enq( item );
  121.     }
  122. }
  123.  
  124. void
  125. SimulationMultiplexor::addWithDelay(Thread *who, double delay)
  126. {
  127.     delay += CurrentSimulatedTime;
  128.     addAt(who, delay);
  129. }
  130.  
  131. //
  132. //    Advance time. Assumes all other CPUs are idle, so no locking
  133. //    on event structures is needed.
  134. //
  135. int
  136. SimulationMultiplexor::advanceTime()
  137. {
  138.     assert( NOTREACHED );
  139.     return( 0 );
  140. }
  141.  
  142. void
  143. SimulationMultiplexor::await(double when)
  144. {
  145.     DEBUG_START;
  146.     cerr << ThisCpu -> name() << "await " << when;
  147.     cerr << " at " << CurrentSimulatedTime << "\n";
  148.     DEBUG_END;
  149.  
  150.     if (when > CurrentSimulatedTime) {
  151.  
  152.     addAt( ThisCpu -> currentThread, when );
  153.  
  154.     Thread *next = ThisCpu -> remove();
  155.  
  156.     if ( next == 0 ) {
  157.         ThisCpu -> raise( &(ThisCpu -> iveSuspendedException) );
  158.     } else {
  159.         Thread *from = ThisCpu -> currentThread;
  160.         ThisCpu -> currentThread = next;
  161.  
  162. #ifndef NDEBUG
  163.         if (CpuMuxDebugFlag) {
  164.         CpuCerrLock.reserve();
  165.         cerr << ThisCpu -> name();
  166.         cerr << " switch to " << ThisCpu -> currentThread -> name() << "\n";
  167.         CpuCerrLock.release();
  168.         }
  169. #endif    /* NDEBUG */
  170.         from -> pContext.switchContext ( &(ThisCpu -> currentThread -> pContext) );
  171.     }
  172.     }
  173. }
  174.  
  175. void
  176. SimulationMultiplexor::hold(double holdFor)
  177. {
  178.     if (holdFor > 0) {
  179.     DEBUG_START;
  180.     cerr << ThisCpu -> name() << "hold for " << holdFor;
  181.     cerr << " at " << CurrentSimulatedTime << "\n";
  182.     DEBUG_END;
  183.  
  184.     await( CurrentSimulatedTime + holdFor );
  185.     }
  186. }
  187.